package com.phkj.qdh.ui.adapter.basetreenode

import android.widget.CheckBox
import android.widget.RelativeLayout
import com.phkj.qdh.R
import com.phkj.qdh.ui.dialog.BaseInspectTreeSelectDialog
import com.phkj.qdh.utils.node.BaseNode
import com.phkj.qdh.utils.node.BaseNodeProvider
import com.phkj.qdh.utils.node.BaseViewHolder

class BaseTreeContentProvider(val dialog: BaseInspectTreeSelectDialog) : BaseNodeProvider() {
    override val itemViewType: Int
        get() = 2
    override val layoutId: Int
        get() = R.layout.item_employee_select_content

    override fun convert(helper: BaseViewHolder, item: BaseNode) {
        val data = item as BaseSortContentNode
        val cb = helper.getView<CheckBox>(R.id.cb)
        helper.setText(R.id.tv_name, item.content.name)
        cb.setOnCheckedChangeListener(null)
        cb.isChecked = item.isSelected
        helper.getView<RelativeLayout>(R.id.ll).setOnClickListener {
            dialog.nodeList.forEach { head ->
                head as BaseSortHeadNode
                head.isSelected = false
                head.child?.forEach { child ->
                    child as BaseSortContentNode
                    child.isSelected = false
                }
            }

            item.isSelected = true
            cb.isChecked = item.isSelected
            getAdapter()?.notifyDataSetChanged()

        }
    }
}